/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.Conta;
import controller.ContaCorrente;
import controller.ContaInvestimento;
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;

/**
 *
 * @author Carol
 */
public class frm_deposito extends javax.swing.JFrame {
    
    public Conta conta;
    public int tipoConta;
    public DecimalFormat df = new DecimalFormat("0.00");
    /**
     * Creates new form frm_deposito
     */
    public frm_deposito() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setTitle("Banco Internacional de TADS - Depósito");
    }

    public frm_deposito(Conta conta, int tipoConta){
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setTitle("Banco Internacional de TADS - Depósito");
        this.conta = conta;
        this.tipoConta = tipoConta;
        lblNumConta.setText(Integer.toString(conta.getNconta()));
        if(tipoConta == 1){
            ContaCorrente cc = (ContaCorrente) conta;
            lblValorDepMin.setText(("-"));
        }else{
            ContaInvestimento ci  = (ContaInvestimento) conta;
            lblValorDepMin.setText(df.format(ci.getDepmin()));
        }
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblContaNo = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblNumConta = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblDepositoMinimo = new javax.swing.JLabel();
        lblValorDepMin = new javax.swing.JLabel();
        lblDigiteValorDeposito = new javax.swing.JLabel();
        txtValorDeposito = new javax.swing.JTextField();
        cmdDepositar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lblContaNo.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        lblContaNo.setText("Conta nº");

        lblNumConta.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        lblNumConta.setText("X");

        lblDepositoMinimo.setText("Depósito Minimo:");

        lblValorDepMin.setText("XX,XX");

        lblDigiteValorDeposito.setText("Digite o valor do depósito:");

        cmdDepositar.setText("Depositar");
        cmdDepositar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                cmdDepositarMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lblDepositoMinimo)
                                .addGap(115, 115, 115)
                                .addComponent(lblValorDepMin))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lblDigiteValorDeposito)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtValorDeposito, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(cmdDepositar)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDepositoMinimo)
                    .addComponent(lblValorDepMin))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDigiteValorDeposito)
                    .addComponent(txtValorDeposito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(cmdDepositar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblContaNo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNumConta)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jSeparator1)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblContaNo)
                    .addComponent(lblNumConta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmdDepositarMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdDepositarMouseReleased
        if(tipoConta == 1){
            ContaCorrente cc = (ContaCorrente) conta;
            try {
                boolean resposta = cc.deposita(Double.parseDouble(txtValorDeposito.getText()));
                if(resposta){
                    //manda mensagem de ok!
                    JOptionPane.showMessageDialog(null, "Depósito efetuado com sucesso.","Operação Concluída", JOptionPane.INFORMATION_MESSAGE); 
                    frm_saldo tela = new frm_saldo(conta.getNconta());
                    tela.show();
                    this.dispose();
                }
            } catch (Exception ex) {
                Logger.getLogger(frm_deposito.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else{
            ContaInvestimento ci = (ContaInvestimento) conta;
            try {
                boolean resposta = ci.deposita(Double.parseDouble(txtValorDeposito.getText()));
                if(resposta){
                    //manda mensagem de ok!
                    JOptionPane.showMessageDialog(null, "Depósito efetuado com sucesso.","Operação Concluída", JOptionPane.INFORMATION_MESSAGE); 
                    frm_saldo tela = new frm_saldo(conta.getNconta());
                    tela.show();
                    this.dispose();
                }
            } catch (Exception ex) {
                Logger.getLogger(frm_deposito.class.getName()).log(Level.SEVERE, null, ex);
            }
        
        
        }
    }//GEN-LAST:event_cmdDepositarMouseReleased

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        frm_saldo tela = new frm_saldo(conta.getNconta());
        tela.show();
        this.dispose();
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frm_deposito.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frm_deposito.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frm_deposito.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frm_deposito.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frm_deposito().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdDepositar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblContaNo;
    private javax.swing.JLabel lblDepositoMinimo;
    private javax.swing.JLabel lblDigiteValorDeposito;
    private javax.swing.JLabel lblNumConta;
    private javax.swing.JLabel lblValorDepMin;
    private javax.swing.JTextField txtValorDeposito;
    // End of variables declaration//GEN-END:variables
}
